package com.yuyou.train.admin.controller;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yuyou.train.admin.service.ICommDataConfigService;
import com.yuyou.train.service.api.admin.entity.CommDataConfig;
import com.yuyou.train.util.bean.ReturnResult;
import com.yuyou.train.util.enums.admin.CommDataConfigEnums;
import com.yuyou.train.util.enums.admin.CommDataConfigEnums.category;

@Validated
@RestController
@RequestMapping(value="/api/commDataConfig")
public class CommDataConfigController  {

	@Autowired
	private ICommDataConfigService commDataConfigService;
	
	
	@ApiOperation(value="获取数据字典")
	@ApiImplicitParam(name = "category", value = "类别：01：地区，02：科目，03：学员学段，04：导师学段，05：题目标签类型，06：试卷类型，07：个人标签，08勋章类型，09：资源类型", paramType="query",required = false)
	@RequestMapping(value="/findDataByCategory",method = {RequestMethod.GET, RequestMethod.POST})
	public ReturnResult<Map<String,List<CommDataConfig>>> findDataByCategory(String category){
		Map<String,List<CommDataConfig>> resMap=new HashMap<String,List<CommDataConfig>>();
		if(!StringUtils.isEmpty(category)){
			List<CommDataConfig> list=commDataConfigService.findUseByCategory(category);
			resMap.put(CommDataConfigEnums.category.getCodeByValue(category), list);
		}else{
			for (category e : CommDataConfigEnums.category.values()) {
				String value=e.getValue();
				List<CommDataConfig> list=commDataConfigService.findUseByCategory(value);
				resMap.put(e.getValue(), list);
			}
		}
		return ReturnResult.success(resMap);
	}
	



}
